addpath C:\Users\Annika\Documents\AAMH\Data2022\
addpath C:\Users\Annika\Documents\AAMH\Results2022\




[num,txt,raw] = xlsread('time.xlsx');
yearlab = num(1:141);

X5 = [IP_AUS;IP_CAN;IP_CHE;...
    IP_GBR;IP_JAP;IP_NZL;IP_SWE;IP_USA];

% y is depvar Nx1
% x is indep var NxK
% g is NxM group indeces (Nx1 for one-way clustering
% so what is "model"? 'linear'
% N is 282


y = [PT_AUS;PT_CAN;PT_CHE;PT_GBR;PT_JAP;PT_NZL;PT_SWE;PT_USA];
%N = size(y,1);
countries = 8;
T = 141
%FE = zeros(countries*T,countries-1);
N1 = 141;

X1 = [Sigma_IP_AUS;Sigma_IP_CAN;Sigma_IP_CHE;...
    Sigma_IP_GBR;Sigma_IP_JAP;Sigma_IP_NZL;Sigma_IP_SWE;Sigma_IP_USA];
X2 = [Sigma_XR_AUS;Sigma_XR_CAN;Sigma_XR_CHE;...
    Sigma_XR_GBR;Sigma_XR_JAP;Sigma_XR_NZL;Sigma_XR_SWE;Sigma_XR_USA];
X3 = [AR_XR_AUS;AR_XR_CAN;AR_XR_CHE;...
    AR_XR_GBR;AR_XR_JAP;AR_XR_NZL;AR_XR_SWE;AR_XR_USA];
X4 = [AR_IP_AUS;AR_IP_CAN;AR_IP_CHE;...
    AR_IP_GBR;AR_IP_JAP;AR_IP_NZL;AR_IP_SWE;AR_IP_USA];
X5 = [IP_AUS;IP_CAN;IP_CHE;...
    IP_GBR;IP_JAP;IP_NZL;IP_SWE;IP_USA];
X6 = [XR_AUS;XR_CAN;XR_CHE;...
    XR_GBR;XR_JAP;XR_NZL;XR_SWE;XR_USA];
X = [FE,X1,X2,X3,X4,X5,X6,Y_HP];
XX = [FE,X2,X3,Y_HP];
g = zeros(1128,2);
N1 = 141;
g(1:N1,1)=yearlab(1:141,1);
g(N1+1:2*N1,1)= yearlab(1:141,1);
g(2*N1+1:3*N1,1)= yearlab(1:141,1);
g(3*N1+1:4*N1,1)= yearlab(1:141,1);
g(4*N1+1:5*N1,1)= yearlab(1:141,1);
g(5*N1+1:6*N1,1)= yearlab(1:141,1);
g(6*N1+1:7*N1,1)= yearlab(1:141,1);
g(7*N1+1:8*N1,1)= yearlab(1:141,1);
%g(9*N1+1:10*N1,1)= yearlab(1:141,1);
%g(10*N1+1:11*N1,1)= yearlab(1:141,1);
g(1:N1,2) = 1;
g(N1+1:2*N1,2) = 2;
g(2*N1+1:3*N1,2) = 3;
g(3*N1+1:4*N1,2) = 4;
g(4*N1+1:5*N1,2) = 5;
g(5*N1+1:6*N1,2) = 6;
g(6*N1+1:7*N1,2) = 7;
g(7*N1+1:8*N1,2) = 8;

%g(9*N1+1:10*N1,2) = 10;

[res, varBhat, Rsq] = clusterreg(y, X, g, 'linear')
%g(10*N1+1:11*N1,2) = 11;
% gör labels för g; de behövs
%[res, varBhat, Rsq] = clusterreg(y, XX, g, 'linear')